package com.stoa.floatlib.utils

open class SingletonHolder<out T, in R>(private val creator: (R) -> T) {

    @Volatile
    private var instance: T? = null

    fun getInstance(arg: R): T =
        instance ?: synchronized(SingletonHolder::class.java) {
            instance ?: creator(arg).apply {
                instance = this
            }
        }

}